package com.sxkf.template.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxkf.core.api.vo.R;
import com.sxkf.template.entity.PostNotice;
import com.sxkf.template.service.PostNoticeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 帖子通知 前端控制器
 * </p>
 *
 * @author 杨玉龙
 * @since 2024-08-20 11:48:57
 */
@Api(tags = "动态（帖子）通知")
@RestController
@RequestMapping("/postNotice")
public class PostNoticeController {
    @Resource
    private PostNoticeService postNoticeService;

    @ApiOperation(value = "分页查询帖子通知")
    @GetMapping(value = "/page")
    public R<IPage<PostNotice>> page(@RequestParam Integer pageNo,
                                      @RequestParam Integer pageSize,
                                     @RequestParam String userId){
        Page<PostNotice> result = postNoticeService.page(new Page<>(pageNo, pageSize),
                new LambdaQueryWrapper<PostNotice>()
                        .eq(PostNotice::getUserId,userId)
                        .eq(PostNotice::getState, "0")
                        .orderByDesc(PostNotice::getCreateTime));
        return R.success(result);
    }

    @ApiOperation(value = "阅读通知")
    @GetMapping(value = "/read")
    public R<?> read(@RequestParam String id){
        postNoticeService.update(new LambdaUpdateWrapper<PostNotice>()
                .set(PostNotice::getState,"1")
                .eq(PostNotice::getId,id));
        return R.success();
    }
}
